package kuang;

/**
 * @author cyt
 * @create 2020-03-07 11:02
 */
// 根据标志位， 和自定义的外部方法， 停止进程。
public class StopThread implements Runnable {

    private boolean f = true;

    @Override
    public void run() {
        int i = 0;
        System.out.println(f);
        while (f) {
            System.out.println(Thread.currentThread().getName() + "运行-----》" + i++);
        }
    }

    public void stopthread() {
        this.f = false;
    }


    public static void main(String[] args) {

        StopThread stopThread = new StopThread();
        new Thread(stopThread).start();

        for (int i = 0; i < 1000; i++) {
            System.out.println("main" + i);
            if (i == 900) {
                stopThread.stopthread();
                System.out.println("线程停止");
            }
        }
    }
}
